package com.cdream.bank2.seata.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdream.bank.domain.AccountInfo;
import com.cdream.bank2.seata.mapper.AccountInfoMapper;
import com.cdream.bank2.seata.service.AccountInfoService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zs
 * @since 2021-08-29
 */
@Service
@Slf4j
public class AccountInfoServiceImpl extends ServiceImpl<AccountInfoMapper, AccountInfo> implements AccountInfoService {
    @Autowired
    private AccountInfoMapper accountInfoMapper;
    @Override
    @Transactional
    public void updateAccountBalance(String accountNo, Double amount) {
        log.info("******** Bank2 Service Begin ... xid: {}", RootContext.getXID());
        //李四增加金额
        accountInfoMapper.updateAccountBalance(accountNo, amount);
        //制造异常
        if (amount == 2) {
            throw new RuntimeException("bank1 make exception 2");
        }
    }

}
